#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 银联行业码支付功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

from examples.base_example import BaseExample
from jlpay.services.trans.union.union_js_pay_service import UnionJsPayService
from jlpay.model.trans.union.union_js_pay import UnionJsPayRequest


class UnionJsPayExample(BaseExample):
    """银联行业码支付示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.union.union_js_pay")
        self.service = UnionJsPayService(self.config)
    
    def build_union_js_pay_request(self):
        """
        构建银联行业码支付请求
        
        Returns:
            UnionJsPayRequest实例
        """
        request = UnionJsPayRequest()
        request.set_mch_id("849584358120018")
        request.set_term_no("60131234")
        request.set_pay_type("unionpay")
        request.set_app_up_identifier("UnionPay/1.0")
        request.set_user_auth_code("gg47vT2aCMw/utQcfQw==")
        request.set_user_id("test_user_001")
        request.set_out_trade_no("ld201911023465529")
        request.set_payment_valid_time("10")
        request.set_body("测试银联行业码支付商品")
        request.set_attach("测试银联行业码支付描述")
        request.set_total_fee("1")
        request.set_remark("测试银联行业码支付备注")
        request.set_notify_url("https://help.jlpay.com/api/docs/home")
        request.set_op_user_id("test_user")
        request.set_op_shop_id("GD_SZ_001")
        request.set_device_info("N50007A8890")
        request.set_mch_create_ip("127.0.0.1")
        request.set_longitude("116.397128")
        request.set_latitude("39.916527")
        request.set_front_url("https://example.com/success")
        request.set_front_fail_url("https://example.com/fail")
        request.set_qr_code("https://example.com/qr")
        return request
    
    def union_js_pay_demo(self):
        """银联行业码支付示例"""
        self.logger.info("开始执行银联行业码支付示例")
        
        # 构建请求
        request = self.build_union_js_pay_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.service.union_js_pay, 
            "银联行业码支付",
            request
        )
        
        self.logger.info("银联行业码支付示例执行完毕")


def main():
    """主函数"""
    example = UnionJsPayExample()
    example.union_js_pay_demo()


if __name__ == "__main__":
    main() 